package com.shunhe.storage.ui.order_receive;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;

import androidx.appcompat.app.AlertDialog;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.ruitu.router_module.support.view.LinearItemDecoration;
import com.ruitu.router_module.util.AlertUtil;
import com.shunhe.storage.R;
import com.shunhe.storage.base.BaseReceiveOrderActivity;
import com.shunhe.storage.dao.model.Goods;
import com.shunhe.storage.dao.model.RepoStaff;

import java.util.ArrayList;
import java.util.List;

// 入库详情页面
public class ReceiveOrderInDetailActivity extends BaseReceiveOrderActivity {

    @Override
    protected int getLayoutRes() {
        return R.layout.activity_receive_order_in_detail;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        rcv_list = findViewById(R.id.rcv_list);
        tv_sel_staff = findViewById(R.id.tv_sel_staff);

        setHeadTitle("入库接单");

        LinearLayoutManager manager = new LinearLayoutManager(this);
        adapter = new ReceiveOrderOutDetailAdapter(this);
        LinearItemDecoration divider = new LinearItemDecoration.Builder(this)
                .setSpan(R.dimen.deco_10_dp)
                .setColorResource(R.color.divider_list)
                .build();
        rcv_list.addItemDecoration(divider);
        rcv_list.setLayoutManager(manager);
        rcv_list.setAdapter(adapter);
        for (int i = 0; i < 3; i++) {
            Goods goods = new Goods();
            List<Goods.StorageBin> binList = new ArrayList<>();
            for (int j = 0; j < 2; j++) {
                binList.add(new Goods.StorageBin());
            }
            goods.setBinList(binList);
            goodsList.add(goods);
        }
        adapter.setDataList(goodsList);

        setListeners();

        for (int i = 0; i < 16; i++) {
            RepoStaff staff = new RepoStaff();
            staff.setName("库管姓名" + i);
            staff.setDesc("库管信息" + i);
            staffList.add(staff);
        }
        staffAdapter = new RepoStaffListAdapter();

        alert = new AlertDialog.Builder(this, R.style.Dialog_FS).create();

    }

    private void setListeners() {
        setOnClickListener(tv_sel_staff);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        if (v == tv_sel_staff) {
//            ToastUtils.showShort("选择入库人");
            showDialog();
        }
    }

    public void showDialog() {// 显示弹窗
        alert.show();
        alert_view = View.inflate(this, R.layout.alert_sel_staff_layout, null);
        sp_sel = alert_view.findViewById(R.id.sp_sel);
        sp_sel.setAdapter(staffAdapter);
        sp_sel.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                currStaff = staffList.get(i);
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {

            }
        });
        alert_view.findViewById(R.id.tv_ok).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                tv_sel_staff.setText(currStaff.getName());
                alert.dismiss();
            }
        });

        AlertUtil.setAlertCenterStyle(alert.getWindow(), alert_view, this);
    }
}